package com.jinzhi.api.controller.aunt;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.JazCoursesChapterDO;
import com.jinzhi.jzweb.domain.JazCoursesDO;
import com.jinzhi.jzweb.domain.JazCoursesOrderDO;
import com.jinzhi.jzweb.domain.JazShippingAddressDO;
import com.jinzhi.jzweb.service.JazCoursesOrderService;
import com.jinzhi.jzweb.service.JazCoursesService;
import com.jinzhi.jzweb.service.JazShippingAddressService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: mcf
 * @CreateTime: 2024/05/16
 * @Description: 课程地址管理 Controller
 */
@Controller
@RequestMapping("/api/auntAddress")
@Api(value = "阿姨端课程地址管理", tags = "阿姨端课程地址管理")
public class AuntAddressController {

    private final JazShippingAddressService jazShippingAddressService;



    public AuntAddressController(JazShippingAddressService jazShippingAddressService){
        this.jazShippingAddressService = jazShippingAddressService;

    }

    @ApiOperation(value = "修改收货地址", notes = "修改收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "receivingName", value = "姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = true, dataType = "String"),
            @ApiImplicitParam(name = "province", value = "省", required = true, dataType = "String"),
            @ApiImplicitParam(name = "city", value = "市", required = true, dataType = "String"),
            @ApiImplicitParam(name = "district", value = "区", required = true, dataType = "String"),
            @ApiImplicitParam(name = "address", value = "详细地址", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/updateAddress")
    public Result<?> updateAddress(String addressId, String receivingName, String phone, String province, String city,
                                                      String district, String address){

        return jazShippingAddressService.updateAddress(addressId,receivingName,phone,province,city,district,address);
    }



    @ApiOperation(value = "新增收货地址", notes = "新增收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "receivingName", value = "姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = true, dataType = "String"),
            @ApiImplicitParam(name = "province", value = "省", required = true, dataType = "String"),
            @ApiImplicitParam(name = "city", value = "市", required = true, dataType = "String"),
            @ApiImplicitParam(name = "district", value = "区", required = true, dataType = "String"),
            @ApiImplicitParam(name = "address", value = "详细地址", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/saveAddress")
    public Result<?> saveAddress(String receivingName, String phone, String province, String city,
                                                     String district, String address) {

        return jazShippingAddressService.saveIntegralUserShippingAddress(receivingName,phone,province,city,district,address);
    }


    @ApiOperation(value = "设置默认地址", notes = "设置默认地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/setIsDefault")
    public Result<?> setIsDefault(String addressId, String userId) {

        return jazShippingAddressService.setIsDefault(addressId,userId);
    }



    @ApiOperation(value = "删除指定地址", notes = "删除指定地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/delAddress")
    public Result<?> delAddress(String addressId) {

        return jazShippingAddressService.delAddress(addressId);
    }



    @ApiOperation(value = "查询用户的收货地址", notes = "查询用户的收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页（1）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页大小（999）", required = true, dataType = "Integer"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/selectByAddress")
    public Result<?> selectByAddress(String current, String size) {

        return jazShippingAddressService.selectByAddress(current,size);
    }


    @ApiOperation(value = "地址详情", notes = "地址详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addressId", value = "地址id", required = true, dataType = "String"),
    })
    @ApiResponses({@ApiResponse(code = 0, message = "操作成功",response = JazShippingAddressDO.class),
            @ApiResponse(code = 500, message = "服务器内部异常")})
    @ResponseBody
    @PostMapping("/addressDetail")
    public Result<?> addressDetail(String addressId) {
        return Result.ok(jazShippingAddressService.selectById(addressId));
    }



}
